package festival.input;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class InputListener implements KeyListener {
    private Action mAction;
    private int mKeyCode;
    private String mDescription;
    
    public InputListener(int keyCode, Action action) {
        mKeyCode = keyCode;
        mAction = action;
    }
    
    public void setDescription(String desc) {
        mDescription = desc;
    }
    
    public void keyPressed(KeyEvent event) {
        if(mKeyCode == event.getKeyCode()) {
            mAction.doAction();
        }
    }
    
    public void keyReleased(KeyEvent event) {
    }

    public void keyTyped(KeyEvent event) {
    }
    
    public int getKeyCode() {
        return mKeyCode;
    }
    
    public void doAction() {
        mAction.doAction();
    }
    
    public String getKeyString() {
        switch(mKeyCode) {
            case KeyEvent.VK_ESCAPE :
                return "ESC";
            case KeyEvent.VK_TAB :
                return "TAB";
            default :
                return ((char)mKeyCode + "").toUpperCase();
        }
    }
    
    public String getDescription() {
        return mDescription;
    }
    
    public String getFullDescription() {
        return getKeyString() + " - " + getDescription();
    }
}
